package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author by mycp
 * @Classname StrategyServiceImpl
 * @Description TODO
 * @Date 2018/11/7 22:04
 */
@Service
public class StrategyServiceImpl implements IStrategyService {

    @Autowired
    private StrategyMapper strategyMapper;

    @Override
    public PageInfo query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Strategy> list = strategyMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        // 判断是更新还是保存操作
        if (strategy.getId() == null){
            strategyMapper.insert(strategy);
        } else {
            strategyMapper.updateByPrimaryKey(strategy);
        }
    }

    @Override
    public Object selectEnable() {
        List<Strategy> list =  strategyMapper.selectEnable();
        return list;
    }

    @Override
    public PageInfo queryEnable(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Strategy> list = strategyMapper.queryEnable(qo);
        return new PageInfo(list);
    }

    @Override
    public Strategy get(Long id) {
        return strategyMapper.selectByPrimaryKey(id);
    }
}
